package com.example.demo.service;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.example.demo.entity.Person;
import com.example.demo.repository.PersonRepository;

@Service
public class PersonService {

	@Resource
	private PersonRepository personRepository;
	
	
	@Transactional //增删改都加上这个，如果是查询，一定不能加
	public Person insert(Person p) {
		return personRepository.save(p);
	}
	@Transactional 
	public void deleteById(Integer id) {
		personRepository.delete(id);
	}
	
	public Person findOne(Integer id) {
		return personRepository.findOne(id);
	}
	
	public List<Person> findAll() {
		return personRepository.findAll();
	}
	
	@Transactional //增删改都加上这个，如果是查询，一定不能加
	public Person update(Person p) {
		return personRepository.save(p);
	}
	
}
